package top.songxs.gmall.product.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Authorization;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import top.songxs.gmall.common.result.Result;
import top.songxs.gmall.common.result.ResultCodeEnum;
import top.songxs.gmall.product.entity.BaseTrademark;
import top.songxs.gmall.product.service.BaseTrademarkService;

import java.util.List;

@RestController
@RequestMapping("/admin/product")
public class BaseTrademarkController {
    @Autowired
    private BaseTrademarkService baseTrademarkService;

    @GetMapping("/baseTrademark/{page}/{limit}")
    public Result<Page<BaseTrademark>> findBaseTrademarkByPage(@PathVariable("page") Long page, @PathVariable("limit") Long limit){
        //http://api.gmall.com/admin/product/baseTrademark/{page}/{limit}
        Page<BaseTrademark> result = baseTrademarkService.findBaseTrademarkByPage(page,limit);
        return Result.build(result, ResultCodeEnum.SUCCESS);
    }

    /**
     * http://api.gmall.com/admin/product/baseTrademark/get/{id}
     * 品牌Id
     * get
     */
    @GetMapping("/baseTrademark/get/{id}")
    public Result<BaseTrademark> getBaseTrademarkById( @PathVariable("id") Long id){
        BaseTrademark byId = baseTrademarkService.getById(id);
        return Result.build(byId, ResultCodeEnum.SUCCESS);
    }


    /**
     * http://api.gmall.com/admin/product/baseTrademark/save
     * {tmName: "锤子。", logoUrl: "/static/default.jpg"}
     * post
     */

    @PostMapping("/baseTrademark/save")
    public Result saveBaseTrademark(@RequestBody BaseTrademark baseTrademark){
        baseTrademarkService.save(baseTrademark);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }

    /**
     * http://api.gmall.com/admin/product/baseTrademark/update
     * baseTrademark的json字符串
     * put
     */
    @PutMapping("/baseTrademark/update")
    public Result updateBaseTrademark( @RequestBody BaseTrademark baseTrademark){
        baseTrademarkService.updateById(baseTrademark);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }


    /**
     * http://api.gmall.com/admin/product/baseTrademark/remove/{id}
     * 品牌Id
     * delete
     */
    @DeleteMapping("/baseTrademark/remove/{id}")
    public Result deleteBaseTrademarkById(@PathVariable("id") Long id){
        baseTrademarkService.removeBaseTrademarkById(id);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }

    //http://api.gmall.com/admin/product/baseTrademark/getTrademarkList

    @GetMapping("/baseTrademark/getTrademarkList")
    public Result<List<BaseTrademark>> findAllBaseTrademark( ){
        List<BaseTrademark> list = baseTrademarkService.list();
        return Result.build(list, ResultCodeEnum.SUCCESS);
    }
























}
